// 2013-9-14下午12:18:46  net.betou.core.service.AgencyOrProxyAbstract.java

package net.betou.core.service;

import java.util.List;
import java.util.Set;

import net.betou.trade.entity.main.AgentAndAdmins;
import net.betou.trade.entity.main.Role;
import net.betou.trade.main.manager.role.AgencyRoleMng;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 
 * @author 叶装装
 */
public  abstract class AgencyOrProxyAbstract implements AgencyOrProxyListener{
	
	protected List< Role > getList( Boolean allowRead ){
		
		if( allowRead == null ){
			return mng.findListByAllowInitToAgency( );
		}
		
		return mng.findListByAllowInitToProxy( );
	}
	
	protected Role copyRole( Role currentRole, AgentAndAdmins bean ){
		
		Role role = new Role( );
		
		Integer level = currentRole.getLevel( );
		String name = currentRole.getName( );
		Set< String > perms = currentRole.getPerms( );
		
		role.initToDefault( getIdentity( currentRole ), name, bean, level, perms );
		
		return role;
	}
	
	private String getIdentity( Role role ){
		String identity = role.getIdentity( );
		
		if( StringUtils.isBlank( identity )){
			return null;
		}
		
		return identity + "d";
	}
	
	@Autowired
	private AgencyRoleMng mng;

}
